<!-- build time:Tue Dec 17 2019 19:26:42 GMT+0800 (GMT+08:00) --><!doctype html><html class="theme-next mist" lang="zh-Hans"><head><meta name="generator" content="Hexo 3.8.0"><meta name="google-site-verification" content="7Tau9WyVgxnsEY9oYedu9g0U6_8akOX3wiKbaYcrg9A"><meta name="baidu-site-verification" content="EVwLiaxdxX"><link href="/css/xps13.css" rel="stylesheet" type="text/css"><link href="/css/message.css" rel="stylesheet" type="text/css"><script type="text/javascript" src="/js/jquery-1.11.3.min.js"></script><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css"><link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css"><meta name="keywords" content="Spring,Spring Cloud,"><link rel="alternate" href="/atom.xml" title="MrBird" type="application/atom+xml"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1"><meta name="description" content="Spring Cloud Config可以对微服务配置进行统一的外部管理，并且默认采用Git来管理配置信息。相对于传统的每个微服务对应一份自个儿的配置文件来说，通过Spring Cloud Config统一管理所有微服务配置具有如下优点：1.集中管理微服务配置，当微服务数量众多的时候，使用这种方式会更为方便；2.通过Git管理微服务配置，方便追踪配置修改记录；3.可以在应用运行期间修改配置，微服务"><meta name="keywords" content="Spring,Spring Cloud"><meta property="og:type" content="article"><meta property="og:title" content="Spring Cloud Config统一配置管理"><meta property="og:url" content="http://mrbird.cc/Spring-Cloud-Config.html"><meta property="og:site_name" content="MrBird"><meta property="og:description" content="Spring Cloud Config可以对微服务配置进行统一的外部管理，并且默认采用Git来管理配置信息。相对于传统的每个微服务对应一份自个儿的配置文件来说，通过Spring Cloud Config统一管理所有微服务配置具有如下优点：1.集中管理微服务配置，当微服务数量众多的时候，使用这种方式会更为方便；2.通过Git管理微服务配置，方便追踪配置修改记录；3.可以在应用运行期间修改配置，微服务"><meta property="og:locale" content="zh-Hans"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181105110354.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181105113317.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181105113615.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181105113754.png"><meta property="og:image" content="http://mrbird.cc/img/20181105140444.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181115151433.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181115151650.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181115162507.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181115163145.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181116091035.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181116091227.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181116092757.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181116100151.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181116100843.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181116110316.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181116110615.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181116110717.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181116114406.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181116135751.png"><meta property="og:image" content="http://mrbird.cc/img/QQ截图20181116141115.png"><meta property="og:updated_time" content="2019-10-28T12:14:46.278Z"><meta name="twitter:card" content="summary"><meta name="twitter:title" content="Spring Cloud Config统一配置管理"><meta name="twitter:description" content="Spring Cloud Config可以对微服务配置进行统一的外部管理，并且默认采用Git来管理配置信息。相对于传统的每个微服务对应一份自个儿的配置文件来说，通过Spring Cloud Config统一管理所有微服务配置具有如下优点：1.集中管理微服务配置，当微服务数量众多的时候，使用这种方式会更为方便；2.通过Git管理微服务配置，方便追踪配置修改记录；3.可以在应用运行期间修改配置，微服务"><meta name="twitter:image" content="http://mrbird.cc/img/QQ截图20181105110354.png"><script type="text/javascript" id="hexo.configurations">var NexT=window.NexT||{},CONFIG={root:"/",scheme:"Mist",sidebar:{position:"left",display:"always",offset:12,offset_float:0,b2t:!1,scrollpercent:!1},fancybox:!1,motion:!1}</script><title>Spring Cloud Config统一配置管理 | MrBird</title></head><body ondragstart="return!1" class="animsition" lang="zh-Hans" style="overflow-x:hidden;padding-right:280px"><script type="text/javascript" src="/js/mo.min.js"></script><style>@media (min-width:768px) and (max-width:991px){body .header-innerr{width:700px!important}}.header-innerr{margin:0 auto;padding:100px 0 70px;width:880px}@media (min-width:1600px){.container .header-innerr{width:1200px}}.header-innerr{position:relative}.header-innerr{padding:20px 0 0}.header-innerr:after,.header-innerr:before{content:" ";display:table}.header-innerr:after{clear:both}@media (max-width:767px){.header-innerr{width:auto;padding:10px;margin-bottom:-20px}}</style><div class="container sidebar-position-left page-post-detail"><div class="headband"></div><header id="header" class="header"><div class="header-inner"><div class="site-brand-wrapper"><div class="site-meta"><link href="https://fonts.font.im/css?family=Merienda" rel="stylesheet"><div class="custom-logo-site-title"><a href="/" class="brand" rel="start"><span class="logo-line-before"><i></i></span> <span class="site-title" style="font-family:Merienda;font-size:1.3rem">MrBird</span> <span class="logo-line-after"><i></i></span></a></div><p class="site-subtitle"></p></div><div class="site-nav-toggle"><button><span class="btn-bar"></span> <span class="btn-bar"></span> <span class="btn-bar"></span></button></div></div><nav class="site-nav"><ul id="menu" class="menu"><li class="menu-item menu-item-home"><a href="/" rel="section">HOME</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section">ARCHIVES</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section">TAGS</a></li><li class="menu-item menu-item-friends"><a href="/friends/" rel="section">FRIENDS</a></li><div class="sidebar-toggle" style="display:none"><div class="sidebar-toggle-line-wrap"><span class="sidebar-toggle-line sidebar-toggle-line-first"></span> <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span> <span class="sidebar-toggle-line sidebar-toggle-line-last"></span></div></div></ul><div class="site-search"><div class="popup search-popup local-search-popup"><div class="local-search-header clearfix"><span class="search-icon"><i class="fa fa-search"></i> </span><span class="popup-btn-close"><i class="fa fa-times-circle"></i></span><div class="local-search-input-wrapper"><input autocomplete="off" placeholder="Search" spellcheck="false" type="text" id="local-search-input"></div></div><div id="local-search-result"></div></div></div></nav></div><div class="header-innerr"><div class="note info" style="margin:0;letter-spacing:.15px">🐤手把手教你搭建<strong>Spring Cloud微服务权限系统</strong>（从零到部署）：<a style="color:#40dab2;font-weight:600" href="https://www.kancloud.cn/mrbird/spring-cloud" target="_blank">https://www.kancloud.cn/mrbird/spring-cloud</a></div></div></header><main id="main" class="main"><div class="main-inner"><div class="content-wrap"><div id="content" class="content"><div id="posts" class="posts-expand"><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><link itemprop="mainEntityOfPage" href="http://mrbird.cc/Spring-Cloud-Config.html"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content="MrBird"><meta itemprop="description" content=""><meta itemprop="image" content="/images/blogImage.jpg"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="MrBird"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">Spring Cloud Config统一配置管理</h1><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="fa fa-calendar-o"></i> </span><span class="post-meta-item-text">Posted on</span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-06-15T14:05:05+08:00">2018-06-15 </time></span><span></span> <span class="post-meta-divider">|</span> <span class="page-pv"><i class="fa fa-laptop"></i>&nbsp;&nbsp;Visit count <span class="busuanzi-value" id="busuanzi_value_page_pv"></span></span></div></header><div class="post-body" itemprop="articleBody"><p>Spring Cloud Config可以对微服务配置进行统一的外部管理，并且默认采用Git来管理配置信息。相对于传统的每个微服务对应一份自个儿的配置文件来说，通过Spring Cloud Config统一管理所有微服务配置具有如下优点：<strong>1.</strong>集中管理微服务配置，当微服务数量众多的时候，使用这种方式会更为方便；<strong>2.</strong>通过Git管理微服务配置，方便追踪配置修改记录；<strong>3.</strong>可以在应用运行期间修改配置，微服务能够自动更新配置。</p><a id="more"></a><p>Spring Cloud Config包含了服务端Server和客户端Client。服务端用于从Git仓库中加载配置，并且缓存到本地；客户端用于从服务端获取配置信息。所以为了演示Spring Cloud Config，我们先来搭建一个服务端。</p><h2 id="搭建Config-Server"><a href="#搭建Config-Server" class="headerlink" title="搭建Config-Server"></a>搭建Config-Server</h2><p>在搭建Config-Server之前，我们需要创建好一个存储配置文件的Git仓库。这里以码云为例子，创建一个名称为Spring-Cloud-Config的参考，然后往仓库的master分支push四个配置文件：</p><p><img src="img/QQ截图20181105110354.png" alt="QQ截图20181105110354.png"></p><p>四个配置文件中分别都包含了一个<code>message</code>属性：</p><p>febs.yml:</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">message:</span> <span class="string">'default properties (master v1.0)'</span></span><br></pre></td></tr></table></figure><p></p><p>febs-dev.yml:</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">message:</span> <span class="string">'dev properties (master v1.0)'</span></span><br></pre></td></tr></table></figure><p></p><p>febs-test.yml:</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">message:</span> <span class="string">'test properties (master v1.0)'</span></span><br></pre></td></tr></table></figure><p></p><p>febs-pro.yml:</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">message:</span> <span class="string">'pro properties (master v1.0)'</span></span><br></pre></td></tr></table></figure><p></p><p>接着创建一个test分支，同样push这四个配置文件，不过配置文件中<code>message</code>属性的内容末尾都改为了<code>(test v1.0)</code>。</p><p>创建好配置文件仓库后，我们新建一个Spring Boot项目，<code>artifactId</code>为Config-Server，然后引入如下依赖：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependencyManagement</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-dependencies<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>Edgware.SR3<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">type</span>&gt;</span>pom<span class="tag">&lt;/<span class="name">type</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">scope</span>&gt;</span>import<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependencyManagement</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-config-server<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>在入口类中加入<code>@EnableConfigServer</code>注解，开启Spring Cloud Config服务端功能。</p><p>接着配置application.yml：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">spring:</span><br><span class="line">  application:</span><br><span class="line">    name: config-server</span><br><span class="line">  cloud:</span><br><span class="line">    config:</span><br><span class="line">      server:</span><br><span class="line">        git:</span><br><span class="line">          uri: https://gitee.com/mrbird/spring-cloud-config</span><br><span class="line">          username: xxx</span><br><span class="line">          password: xxx</span><br><span class="line">server:</span><br><span class="line">  port: 12580</span><br></pre></td></tr></table></figure><p></p><div class="note info"><p>uri的末尾加不加<code>.git</code>都可以。</p></div><p>配置具体含义如下：</p><ol><li><p><code>spring.cloud.config.server.git.uri</code>：配置了Git仓库的地址，这里用的是码云，当然你也可以使用别的Git代码托管平台；</p></li><li><p><code>spring.cloud.config.server.git.username</code>：仓库用户名，即Git托管平台的用户名；</p></li><li><p><code>spring.cloud.config.server.git.password</code>：仓库密码，即Git托管平台的密码。</p></li></ol><p>这里服务端的端口号为12580。</p><p>启动应用，我们便可以使用下面这些格式来访问配置信息了：</p><ul><li><p><code>/{application}/{profile}[/{label}]</code></p></li><li><p><code>/{application}-{profile}.yml</code></p></li><li><p><code>/{label}/{application}-{profile}.yml</code></p></li><li><p><code>/{application}-{profile}.properties</code></p></li><li><p><code>/{label}/{application}-{profile}.properties</code></p></li></ul><p>比如当我们访问<a href="http://localhost:12580/master/febs-test" target="_blank" rel="noopener">http://localhost:12580/master/febs-test</a>时，响应信息如下所示：</p><p><img src="img/QQ截图20181105113317.png" alt="QQ截图20181105113317.png"></p><p>访问<a href="http://localhost:12580/master/febs-test.yml" target="_blank" rel="noopener">http://localhost:12580/master/febs-test.yml</a>：</p><p><img src="img/QQ截图20181105113615.png" alt="QQ截图20181105113615.png"></p><p>访问<a href="http://localhost:12580/test/febs-test.yml" target="_blank" rel="noopener">http://localhost:12580/test/febs-test.yml</a>：</p><p><img src="img/QQ截图20181105113754.png" alt="QQ截图20181105113754.png"></p><p>至此服务端搭建成功。</p><h2 id="搭建Config-Client"><a href="#搭建Config-Client" class="headerlink" title="搭建Config-Client"></a>搭建Config-Client</h2><p>新建一个Spring Boot项目，<code>artifactId</code>为Config-Client，然后引入如下依赖：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependencyManagement</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-dependencies<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>Edgware.SR3<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">type</span>&gt;</span>pom<span class="tag">&lt;/<span class="name">type</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">scope</span>&gt;</span>import<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependencyManagement</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-config<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>编写一个Controller，用于测试获取Config-Server中配置文件的<code>message</code>属性值：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">TestController</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Value</span>(<span class="string">"$&#123;message&#125;"</span>)</span><br><span class="line">    <span class="keyword">private</span> String message;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@GetMapping</span>(<span class="string">"message"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getMessage</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">this</span>.message;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p></p><p>要想让上面的代码顺利的获取到<code>message</code>属性值，我们还需要在配置文件中进行一些额外配置：</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"><span class="attr">  application:</span></span><br><span class="line"><span class="attr">    name:</span> <span class="string">febs</span></span><br><span class="line"><span class="attr">  cloud:</span></span><br><span class="line"><span class="attr">    config:</span></span><br><span class="line"><span class="attr">      profile:</span> <span class="string">dev</span></span><br><span class="line"><span class="attr">      label:</span> <span class="string">test</span></span><br><span class="line"><span class="attr">      uri:</span> <span class="attr">http://localhost:12580</span></span><br><span class="line"></span><br><span class="line"><span class="attr">server:</span></span><br><span class="line"><span class="attr">  port:</span> <span class="number">12581</span></span><br></pre></td></tr></table></figure><p></p><div class="note danger"><p>值得注意的是，这里配置文件并不是叫application.yml，而是必须命名为bootstrap.yml。</p></div><p>上面配置含义如下：</p><ol><li><p><code>spring.application.name</code>: 对应配置文件规则中的<code>{application}</code>；</p></li><li><p><code>spring.cloud.config.profile</code>: 对应配置文件规则中的<code>{profile}</code>部分；</p></li><li><p><code>spring.cloud.config.label</code>: 对应配置文件规则中的<code>{label}</code>部分；</p></li><li><p><code>spring.cloud.config.uri</code>: 对应Config-Server的地址。</p></li></ol><p>通过上面的配置，<code>message</code>的内容应该是Git仓库中test分支，febs-dev.yml中的<code>message</code>属性值。下面我们来证实一下这个推测。</p><p>启动Config-Client（Config-Server没启动的话得先启动Config-Server），访问<a href="http://localhost:12581/message" target="_blank" rel="noopener">http://localhost:12581/message</a>：</p><p><img src="img/20181105140444.png" alt="QQ截图20181105140444.png"></p><p>结果证实了我们的推测。</p><h2 id="Config-Server额外配置"><a href="#Config-Server额外配置" class="headerlink" title="Config-Server额外配置"></a>Config-Server额外配置</h2><p>上面我们简单的地搭建了一个Config-Server，下面我们来进一步了解Config-Server的可用配置。</p><h3 id="占位符的使用"><a href="#占位符的使用" class="headerlink" title="占位符的使用"></a>占位符的使用</h3><p>在Config-Server中，除了固定配置一个Git仓库地址外，我们也可以使用占位符来灵活的指定Git仓库地址。</p><p>将上面Config-Server的Git仓库地址改为：</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"><span class="attr">  cloud:</span></span><br><span class="line"><span class="attr">    config:</span></span><br><span class="line"><span class="attr">      server:</span></span><br><span class="line"><span class="attr">        git:</span></span><br><span class="line"><span class="attr">          uri:</span> <span class="attr">https://gitee.com/mrbird/&#123;application&#125;</span></span><br></pre></td></tr></table></figure><p></p><p>这里使用占位符<code>{application}</code>来代替上面的spring-cloud-config，通过这种配置，我们可以让不同的Config-Client去不同的Git仓库获取配置。比如，当Config-Client的项目名称为febs的时候，对应Git仓库地址为:<code>https://gitee.com/mrbird/febs</code>，当名称为test时，对应Git仓库地址为:<code>https://gitee.com/mrbird/test</code>。这样我们就可以为不同的项目配置不同的Git仓库。</p><h3 id="子目录支持"><a href="#子目录支持" class="headerlink" title="子目录支持"></a>子目录支持</h3><p>除了使用占位符为每个项目创建单独的Git仓库来存储配置信息外，我们也可以只创建一个Git仓库来存储配置，只不过是将不同的项目配置放置到不同的目录下，只需要像下面这样配置即可：</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"><span class="attr">  cloud:</span></span><br><span class="line"><span class="attr">    config:</span></span><br><span class="line"><span class="attr">      server:</span></span><br><span class="line"><span class="attr">        git:</span></span><br><span class="line"><span class="attr">          uri:</span> <span class="attr">https://gitee.com/mrbird/spring-cloud-config/</span></span><br><span class="line"><span class="attr">          username:</span> <span class="string">xxxx</span></span><br><span class="line"><span class="attr">          password:</span> <span class="string">xxxx</span></span><br><span class="line"><span class="attr">          search-paths:</span> <span class="string">'&#123;application&#125;'</span></span><br></pre></td></tr></table></figure><p></p><p>通过上面的配置，我们可以实现在<code>https://gitee.com/mrbird/spring-cloud-config/</code>仓库中，一个Config-Client对应一个配置目录的效果，即当Config-Client的项目名称为febs的时候，其搜索配置的目录为<code>https://gitee.com/mrbird/spring-cloud-config/febs</code>。</p><div class="note danger"><p>这里search-paths的占位符必须加上单引号<code>&#39;&#39;</code>，否则没办法正确读取配置，具体可参考：<a href="https://blog.csdn.net/weixin_35022258/article/details/79019033" target="_blank" rel="noopener">https://blog.csdn.net/weixin_35022258/article/details/79019033</a></p></div><h3 id="clone-on-start"><a href="#clone-on-start" class="headerlink" title="clone-on-start"></a>clone-on-start</h3><p>默认情况下Config-Server在启动的时候并不会马上就去Git参考clone配置文件，只有当Config-Clinet从Config-Server获取相关配置信息的时候，其才会去进行clone操作。我们可以将<code>clone-on-start</code>属性设置为<code>true</code>，其Config-Server在启动的时候就进行clone操作：</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">spring</span></span><br><span class="line"><span class="attr">  cloud:</span></span><br><span class="line"><span class="attr">    config:</span></span><br><span class="line"><span class="attr">      server:</span></span><br><span class="line"><span class="attr">        git:</span></span><br><span class="line"><span class="attr">          clone-on-start:</span> <span class="literal">true</span></span><br></pre></td></tr></table></figure><p></p><p>这样做的好处在于，当Git连接信息有误时，可以马上发现。</p><h3 id="整合Spring-Security"><a href="#整合Spring-Security" class="headerlink" title="整合Spring Security"></a>整合Spring Security</h3><p>Config-Server中包含了Git连接信息，为了使其更加安全，我们可以通过Spring Security来做用户名密码认证。</p><p>在Config-Server中加入Spring Security依赖：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-security<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>然后在Config-Server的配置文件application.yml中加入用户名和密码：</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line"><span class="attr">  user:</span></span><br><span class="line"><span class="attr">    name:</span> <span class="string">mrbird</span></span><br><span class="line"><span class="attr">    password:</span> <span class="number">123456</span></span><br></pre></td></tr></table></figure><p></p><p>与此同时，我们也需要在Config-Client中配置Config-Server的用户名和密码，否则在获取配置的时候将报401错误：</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"><span class="attr">  cloud:</span></span><br><span class="line"><span class="attr">    config:</span></span><br><span class="line"><span class="attr">      username:</span> <span class="string">mrbird</span></span><br><span class="line"><span class="attr">      password:</span> <span class="number">123456</span></span><br></pre></td></tr></table></figure><p></p><h3 id="加密解密"><a href="#加密解密" class="headerlink" title="加密解密"></a>加密解密</h3><p>截至目前为止，Config-Server中Git仓库的密码是直接明文配置的，我们可以对这些敏感信息进行加密处理。在此之前，需要先安装JCE（Java Cryptography Extension），本文使用的是JDK 8，与之对应的JCE下载地址为：<a href="https://www.oracle.com/technetwork/java/javase/downloads/jce-all-download-5170447.html" target="_blank" rel="noopener">https://www.oracle.com/technetwork/java/javase/downloads/jce-all-download-5170447.html</a>：</p><p><img src="img/QQ截图20181115151433.png" alt="QQ截图20181115151433.png"></p><p>解压后，包含三个文件：</p><p><img src="img/QQ截图20181115151650.png" alt="QQ截图20181115151650.png"></p><p>把它们复制到<code>$JAVA HOME/jre/lib/security</code>目录下即可。</p><p><strong>对称加密</strong></p><p>使用对称加密的方式需要在Config-Server中配置加密用的密钥：</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">encrypt:</span></span><br><span class="line"><span class="attr">  key:</span> <span class="string">hello</span></span><br></pre></td></tr></table></figure><p></p><p>配置好后重启Config-Server，访问<a href="http://localhost:12580/encrypt/status" target="_blank" rel="noopener">http://localhost:12580/encrypt/status</a>查看密钥是否配置成功:</p><p><img src="img/QQ截图20181115162507.png" alt="QQ截图20181115162507.png"></p><p>可见配置并未生效，查看Spring-Cloud-Config的Github issue找到了解决办法：<a href="https://github.com/spring-cloud/spring-cloud-config/issues/767" target="_blank" rel="noopener">https://github.com/spring-cloud/spring-cloud-config/issues/767</a>。</p><p>解决办法就是需要将密钥配置在bootstrap.yml中，再次访问<a href="http://localhost:12580/encrypt/status" target="_blank" rel="noopener">http://localhost:12580/encrypt/status</a>：</p><p><img src="img/QQ截图20181115163145.png" alt="QQ截图20181115163145.png"></p><p>假如我们Git仓库的密码为mrbird123，要对其加密的话我们可以使用<code>curl</code>命令来获取加密后的密码：</p><p><img src="img/QQ截图20181116091035.png" alt="QQ截图20181116091035.png"></p><p>因为Config-Server设置了用户名和密码，所以在使用<code>curl</code>命令时，需要带上<code>-u mrbird:123456</code>。</p><p>可看到mrbird123被加密成了<code>f413c4d441a7a00ef82d9aedfab087dae51772276c0201a9d9b13df3e2a9b64c</code>，</p><p>因为是对称加密，所以我们也可以将<code>f413c4d441a7a00ef82d9aedfab087dae51772276c0201a9d9b13df3e2a9b64c</code>解密：</p><p><img src="img/QQ截图20181116091227.png" alt="QQ截图20181116091227.png"></p><p>我们用加密后的密码替换掉Git连接的明文密码：</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"><span class="attr">  cloud:</span></span><br><span class="line"><span class="attr">    config:</span></span><br><span class="line"><span class="attr">      server:</span></span><br><span class="line"><span class="attr">        git:</span></span><br><span class="line"><span class="attr">          password:</span> <span class="string">'&#123;cipher&#125;155315857d26a3235027679a015aa7c71a15ca43ae77e2a11ce9d122d1f4bd043d18'</span></span><br></pre></td></tr></table></figure><p></p><p>使用<code>{cipher}</code>开头表明这是一个加密的内容，Config-Server会自动为其解密。当然，你还可以为任何你想加密的属性值进行加密，不限于密码。</p><p><strong>非对称加密</strong> 非对称加密相比对称加密来说显得更加安全，要生成非对称加密的密码，需要借助<code>keytool</code>命令来生成密钥。keytool是JDK中的一个密钥和证书 管理工具。 位于<code>%JAVA_HOME%\bin\</code>目录下：</p><p><img src="img/QQ截图20181116092757.png" alt="QQ截图20181116092757.png"></p><p>我们使用如下命令来生成一个密钥文件：</p><p><img src="img/QQ截图20181116100151.png" alt="QQ截图20181116100151.png"></p><p>命令执行结束后，会在<code>%JAVA_HOME%\bin\</code>目录下生成一个 config-server.keystore文件。密钥文件的有效期默认为90天，我们可以使用<code>-validity 365</code>来改变其有效天数为365天。</p><p>接着将密钥文件拷贝到Config-Server的resources目录下，然后在bootstrap.yml中添加如下配置：</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#encrypt:</span></span><br><span class="line"><span class="comment">##  key: hello</span></span><br><span class="line"></span><br><span class="line"><span class="attr">encrypt:</span></span><br><span class="line"><span class="attr">  key-store:</span></span><br><span class="line"><span class="attr">    location:</span> <span class="attr">classpath:config-server.keystore</span></span><br><span class="line"><span class="attr">    alias:</span> <span class="string">Config-Server</span></span><br><span class="line"><span class="attr">    password:</span> <span class="number">123456</span></span><br><span class="line"><span class="attr">    secret:</span> <span class="number">654321</span></span><br></pre></td></tr></table></figure><p></p><p>其中<code>encrypt.key-store.password</code>为第一次输入的口令，<code>encrypt.key-store.secret</code>为<code>&lt;Config-Server&gt;</code>的密钥口令的密钥口令。</p><p>我们将Git连接的密码改回明文，然后重启Config-Server，运行如下命令重新对Git连接密码进行加密：</p><p><img src="img/QQ截图20181116100843.png" alt="QQ截图20181116100843.png"></p><p>然后将加密后的密码替换明文密码即可：</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"><span class="attr">  cloud:</span></span><br><span class="line"><span class="attr">    config:</span></span><br><span class="line"><span class="attr">      server:</span></span><br><span class="line"><span class="attr">        git:</span></span><br><span class="line"><span class="attr">          password:</span> <span class="string">'&#123;cipher&#125;AQAjzCKbjLdmgBt+Zm0/jznvbwbCAZ7j1hZKl1NtcmdEj2GFGzF02Bi5jIk9ETz92XOV3z9U5UZTEBMLblKFlZqEzFNooJAZSEmCdwDY9iI5mbhe5oGApxlhbzF4pccF9wtkt4YIW3ElQWCfg01FhDuBiDIZ8NPlMJXRDjIV+/rhla/MkdHVWaphWW3PbHlF95D7bjssCLlyeDB5BjF4orOMpVdVAT/BZA5ANy+xDbEUiOd54E9E9pYAwxG+0qW6a3PvK6OCFozVfPgvT5xorAiJ50AzIH64ZjqILSPonpk3hcIm1PlTguOE5x2BYvgxYmq/CnlkhML07yJVElVAaWh4sTIs8I5hAwQ58SvAcgq/oDE5QluF+dHvoZFn748yCe0='</span></span><br></pre></td></tr></table></figure><p></p><h2 id="Config-Client额外配置"><a href="#Config-Client额外配置" class="headerlink" title="Config-Client额外配置"></a>Config-Client额外配置</h2><h3 id="刷新配置"><a href="#刷新配置" class="headerlink" title="刷新配置"></a>刷新配置</h3><p>在Config-Server和Config-Client都启动后，如果这时候Git仓库存储的配置信息改变了，在不重启Config-Client的情况下，配置信息是不会跟着更新的。那么如何在Git仓库存储的配置得到改变的时候也刷新Config-Client中获取到的配置值呢？很简单，我们只需要对Config-Client进行简单的改造：</p><p>在Config-Client中添加<code>spring-boot-starter-actuator</code>依赖：</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&lt;dependency&gt;</span></span><br><span class="line">    <span class="string">&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span></span><br><span class="line">    <span class="string">&lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;</span></span><br><span class="line"><span class="string">&lt;/dependency&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>该依赖包含了<code>/refresh</code>端点，可以用来刷新配置。</p><p>然后在获取配置的Controller上加入<code>@RefreshScope</code>注解：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@RefreshScope</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">TestController</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Value</span>(<span class="string">"$&#123;message&#125;"</span>)</span><br><span class="line">    <span class="keyword">private</span> String message;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@GetMapping</span>(<span class="string">"message"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getMessage</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">this</span>.message;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p></p><p>值得注意的是，我们需要在Config-Client的配置文件中加入如下配置来关闭认证，否则我们无权访问<code>/refresh</code>端点，具体可见<a href="https://github.com/spring-guides/gs-centralized-configuration/issues/5" target="_blank" rel="noopener">https://github.com/spring-guides/gs-centralized-configuration/issues/5</a>：</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">management:</span></span><br><span class="line"><span class="attr">  security:</span></span><br><span class="line"><span class="attr">    enabled:</span> <span class="literal">false</span></span><br></pre></td></tr></table></figure><p></p><p>重启Config-Client，访问<a href="http://localhost:12581/message" target="_blank" rel="noopener">http://localhost:12581/message</a>:</p><p><img src="img/QQ截图20181116110316.png" alt="QQ截图20181116110316.png"></p><p>这时候我们将Git仓库中对应的配置信息改为<code>测试配置刷新</code>，再次访问<a href="http://localhost:12581/message" target="_blank" rel="noopener">http://localhost:12581/message</a>会发现值还是<code>dev properties (master v1.0)</code>。</p><p>接着我们使用以下命令来刷新配置：</p><p><img src="img/QQ截图20181116110615.png" alt="QQ截图20181116110615.png"></p><p>这时候再次访问<a href="http://localhost:12581/message" target="_blank" rel="noopener">http://localhost:12581/message</a>：</p><p><img src="img/QQ截图20181116110717.png" alt="QQ截图20181116110717.png"></p><p>可看到在不重启Config-Client的前提下配置值已经得到了更新。</p><h2 id="集群配置"><a href="#集群配置" class="headerlink" title="集群配置"></a>集群配置</h2><p>如果Config-Server只是单机部署的话，当其遇到问题宕机后，所有从Config-Server获取配置信息的微服务都无法正常工作了，这是灾难性的。所以我们很有必要对Config-Server进行集群处理。</p><p>集群的方式有很多，这里介绍通过将Config-Server注册到Eureka的方式来搭建集群。</p><p>我们使用在<a href="Spring-Cloud-Eureka.html">Spring Cloud Eureka服务治理</a>一节中的Eureka-Service来构建Eureka-Server服务注册中心，使用以下命令启动Eureka-Server集群：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">java -jar Eureka-Service-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer1</span><br><span class="line">java -jar Eureka-Service-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer2</span><br></pre></td></tr></table></figure><p></p><p>启动后，访问<a href="http://localhost:8080/" target="_blank" rel="noopener">http://localhost:8080/</a>:</p><p><img src="img/QQ截图20181116114406.png" alt="QQ截图20181116114406.png"></p><p>说明Eureka集群启动成功。 接下来开始对Config-Server进行改造，将其注册到Eureka服务注册中心。</p><p>在Config-Server中加入Eureka依赖：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-eureka<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>然后在Config-Server的启动类中加入<code>@EnableDiscoveryClient</code>注解，用于将服务注册到Eureka服务注册中心上：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="meta">@EnableConfigServer</span></span><br><span class="line"><span class="meta">@EnableDiscoveryClient</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">DemoApplication</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        SpringApplication.run(DemoApplication.class, args);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p></p><p>最后在配置类application.yml中指定Eureka服务注册中心的地址：</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">eureka:</span></span><br><span class="line"><span class="attr">  client:</span></span><br><span class="line"><span class="attr">    serviceUrl:</span></span><br><span class="line"><span class="attr">      defaultZone:</span> <span class="attr">http://mrbird:123456@peer1:8080/eureka/,http://mrbird:123456@peer2:8081/eureka/</span></span><br></pre></td></tr></table></figure><p></p><p>因为之前Eureka服务注册中心添加了认证，所以需要在url中指定用户名和密码。</p><p>改造好后，启动Config-Server，再次访问Eureka服务注册中心地址：<a href="http://localhost:8080/" target="_blank" rel="noopener">http://localhost:8080/</a>：</p><p><img src="img/QQ截图20181116135751.png" alt="QQ截图20181116135751.png"></p><p>可看到Config-Server已经成功注册了。</p><p>接着开始改造Config-Client，在其pom中同样引入Eureka依赖：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-eureka<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>然后在bootstrap.yml中指定获取Config-Server服务的地址：</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"><span class="attr">  application:</span></span><br><span class="line"><span class="attr">    name:</span> <span class="string">febs</span></span><br><span class="line"><span class="attr">  cloud:</span></span><br><span class="line"><span class="attr">    config:</span></span><br><span class="line"><span class="attr">      profile:</span> <span class="string">dev</span></span><br><span class="line"><span class="attr">      label:</span> <span class="string">master</span></span><br><span class="line"><span class="attr">      username:</span> <span class="string">mrbird</span></span><br><span class="line"><span class="attr">      password:</span> <span class="number">123456</span></span><br><span class="line"><span class="attr">      discovery:</span></span><br><span class="line"><span class="attr">        enabled:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">        service-id:</span> <span class="string">config-server</span></span><br><span class="line"></span><br><span class="line"><span class="attr">eureka:</span></span><br><span class="line"><span class="attr">  client:</span></span><br><span class="line"><span class="attr">    serviceUrl:</span></span><br><span class="line"><span class="attr">      defaultZone:</span> <span class="attr">http://mrbird:123456@peer1:8080/eureka/,http://mrbird:123456@peer2:8081/eureka/</span></span><br></pre></td></tr></table></figure><p></p><p>其中<code>eureka.client.serviceUrl.defaultZone</code>指定了Eureka服务注册中心的地址；<code>spring.cloud.config.discovery.enabled</code>指定为<code>true</code>开启获取服务的功能，<code>spring.cloud.config.discovery.service-id</code>表明需要获取服务的名称为<code>config-server</code>。</p><p>最后在Config-Client的启动类中引入<code>@EnableDiscoveryClient</code>注解：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="meta">@EnableDiscoveryClient</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">DemoApplication</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        SpringApplication.run(DemoApplication.class, args);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p></p><p>启动Config-Client，访问：<a href="http://localhost:12581/message" target="_blank" rel="noopener">http://localhost:12581/message</a></p><p><img src="img/QQ截图20181116141115.png" alt="QQ截图20181116141115.png"></p><p>可看到，配置信息同样获取成功。</p><p>参考文章：</p><ol><li><p><a href="https://book.douban.com/subject/27025912/" target="_blank" rel="noopener">Spring Cloud微服务实战</a></p></li><li><p><a href="http://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.4.3.RELEASE/single/spring-cloud-config.html" target="_blank" rel="noopener">http://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.4.3.RELEASE/single/spring-cloud-config.html</a></p></li></ol><p>源码地址：<a href="https://github.com/wuyouzhuguli/SpringAll/tree/master/41.Spring-Cloud-Config" target="_blank" rel="noopener">https://github.com/wuyouzhuguli/SpringAll/tree/master/41.Spring-Cloud-Config</a></p><script>$(".post-body a").not(".thispage").addClass("ignore-href").attr("target","_blank")</script></div><div></div><div><div style="padding:10px 0;margin:20px auto;width:90%;text-align:center;color:#878787"><div>请作者喝瓶肥宅水~</div><button id="rewardButton" style="margin-top:10px" disable="enable" onclick='var e=document.getElementById("QR");"none"===e.style.display?e.style.display="block":e.style.display="none"'><span style="height:46px;width:46px;line-height:46px;border-radius:50%;color:#fe5f55;font-weight:600;background:#ffd5be;border:none;box-shadow:0 4px 8px 0 rgba(255,213,190,.4)">￥</span></button><div id="QR" style="display:none"><div id="wechat" style="display:inline-block"><img id="wechat_qr" src="/img/wechat_pay.png" alt="MrBird WeChat Pay"></div><div id="alipay" style="display:inline-block"><img id="alipay_qr" src="/img/ali_pay.png" alt="MrBird Alipay"></div></div></div><style>#QR img{width:auto;margin:.8em 1em 0 1em}</style></div><div><ul class="post-copyright"><li class="post-copyright-author"><strong>本文作者：</strong> MrBird</li><li class="post-copyright-link"><strong>本文链接：</strong> <a href="http://mrbird.cc/Spring-Cloud-Config.html" title="Spring Cloud Config统一配置管理">http://mrbird.cc/Spring-Cloud-Config.html</a></li><li class="post-copyright-license"><strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明出处！</li></ul></div><footer class="post-footer"><div class="post-tags" style="margin-bottom:1.3rem"><a href="/tags/Spring/" rel="tag"># Spring</a> <a href="/tags/Spring-Cloud/" rel="tag"># Spring Cloud</a></div><div class="post-nav"><div class="post-nav-next post-nav-item"><a href="/Spring-Cloud-Zuul-Router.html" rel="next" title="Spring Cloud Zuul服务网关"><i class="fa fa-chevron-left"></i> Spring Cloud Zuul服务网关</a></div><span class="post-nav-divider"></span><div class="post-nav-prev post-nav-item"><a href="/Spring-Cloud-Bus.html" rel="prev" title="使用Spring Cloud Bus刷新配置">使用Spring Cloud Bus刷新配置 <i class="fa fa-chevron-right"></i></a></div></div></footer></article><hr><div id="container"></div><div class="post-spread"><div id="comment-div"></div><style>.valine .vlist{margin-bottom:3rem}.valine .vwrap .vcontrol .col.col-60{text-align:left}.valine .vlist .vcard .vhead,.valine .vlist .vcard section .vfooter{text-align:left}.valine .vlist .vcard section{padding-bottom:.5rem!important}.vname{color:#42b983!important}.valine .vinfo .col{text-align:left;margin-left:-27rem}div#comment-div{margin-bottom:-8rem}.valine .vlist .vcard .vcontent .code,.valine .vlist .vcard .vcontent code,.valine .vlist .vcard .vcontent pre{background:#fbfbfb}.valine .vlist .vcard .vcontent a{color:#42b983}.valine .vlist .vcard .vimg{border-radius:3px}.valine .vbtn{border-radius:2px;padding:.3rem 1.25rem}.valine .vbtn:active,.valine .vbtn:hover{color:#42b983;border-color:#42b983;background-color:#fff}.valine .vwrap .vheader .vinput:focus{border-bottom-color:#42b983}.valine .vlist .vcard .vcontent.expand:before{background:-webkit-gradient(linear,left top,left bottom,from(hsla(0,0%,100%,0)),to(hsla(0,0%,100%,.2)));background:linear-gradient(180deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.2))}.valine .vlist .vcard .vcontent.expand:after{content:"点击展开";font-size:.4rem;text-align:right;left:-1rem;background:hsla(0,0%,100%,.2)}.valine .vlist .vcard section .vfooter .vat{color:#b3b3b3}.valine .vlist .vcard section .vfooter .vat:hover{color:#42b983}.vcontent img{margin:0}.valine .info{display:none}</style><script type="text/javascript" src="/js/av.min.js"></script><script type="text/javascript" src="/js/Valine.min.js"></script><script type="text/javascript" src="/js/activate-power-mode.js"></script><script>POWERMODE.colorful=!0,POWERMODE.shake=!1,document.body.addEventListener("input",POWERMODE),new Valine({el:"#comment-div",notify:!1,verify:!0,appId:"SMcDFP1bN1jgb9Lo8JmtICHm-gzGzoHsz",appKey:"dH4nrUrt3V5XiJiI6Qyejnbi",placeholder:"",path:window.location.pathname,avatar:"monsterid",guest_info:["nick","mail","link"]});var chicken='<a href="#"><img src="https://image.uisdc.com/wp-content/uploads/2018/06/uisdc-chat-chicken.gif" class="checken"></a>';$("#comment-div").prepend(chicken)</script></div></div><script>var $bqinline=$("img[alt='bq-inline']");$bqinline.css({width:"2.3rem",height:"2.3rem",display:"inline","vertical-align":"text-bottom"})</script></div><div class="comments" id="comments"></div></div><aside id="sidebar" class="sidebar" onselectstart="return!1"><div class="sidebar-inner"><ul class="sidebar-nav motion-element"><li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">Contents</li><li class="sidebar-nav-overview" data-target="site-overview">Site Preview</li></ul><section class="site-overview sidebar-panel"><div class="sidebar-sticky sticky"><div itemscope itemtype="http://schema.org/Person"><div class="author__avatar"><img src="/images/blogImage.jpg" class="author__avatar" alt="MrBird" itemprop="image"></div><div class="author__content"><h3 class="author__name" itemprop="name">MrBird's Blog</h3><p class="author__bio" itemprop="description">A simple blog, code repository, just keep blogging</p></div><div class="author__urls-wrapper"><button class="btn btn--inverse">Follow</button><ul class="author__urls social-icons"><li><a href="http://map.baidu.com/?newmap=1&s=s%26wd%3D%E7%A6%8F%E5%B7%9E%E5%B8%82%26c%3D300&from=alamap&tpl=mapcity" target="_blank" itemprop="url" class="ignore-href"><i class="fa fa-fw fa-map-marker" aria-hidden="true"></i>&nbsp;&nbsp;FuZhou,CN</a></li><li><a href="https://love.mrbird.cc" target="_blank" itemprop="url" class="ignore-href"><i class="fa fa-fw fa-diamond" aria-hidden="true"></i>&nbsp;&nbsp;Love</a></li><li><a href="https://cloud.mrbird.cn" target="_blank" itemprop="url" class="ignore-href"><i class="fa fa-fw fa-chain" aria-hidden="true"></i>&nbsp;&nbsp;FEBS</a></li><li><a href="/atom.xml" target="_blank" itemprop="url" class="ignore-href"><i class="fa fa-fw fa-rss" aria-hidden="true"></i>&nbsp;&nbsp;RSS</a></li><li><a href="https://gitee.com/mrbirdd" target="_blank" itemprop="sameAs" class="ignore-href"><i class="fa fa-fw fa-codepen" aria-hidden="true"></i>&nbsp;&nbsp;Gitee</a></li><li><a href="https://github.com/wuyouzhuguli" target="_blank" itemprop="sameAs" class="ignore-href"><i class="fa fa-fw fa-github-alt" aria-hidden="true"></i>&nbsp;&nbsp;GitHub</a></li><li><a href="javascript:;" class="popup-trigger"><i class="fa fa-fw fa-search" aria-hidden="true"></i>&nbsp;&nbsp;Search</a></li></ul></div></div></div><script>var $urls=$(".author__urls").find("a");$urls.each(function(){var o=$(this);o.mouseenter(function(){o.css({color:"#414547"})}),o.mouseleave(function(){o.css({color:""})})})</script></section><section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active"><div class="post-toc"><div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#搭建Config-Server"><span class="nav-number">1.</span> <span class="nav-text">搭建Config-Server</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#搭建Config-Client"><span class="nav-number">2.</span> <span class="nav-text">搭建Config-Client</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Config-Server额外配置"><span class="nav-number">3.</span> <span class="nav-text">Config-Server额外配置</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#占位符的使用"><span class="nav-number">3.1.</span> <span class="nav-text">占位符的使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#子目录支持"><span class="nav-number">3.2.</span> <span class="nav-text">子目录支持</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#clone-on-start"><span class="nav-number">3.3.</span> <span class="nav-text">clone-on-start</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#整合Spring-Security"><span class="nav-number">3.4.</span> <span class="nav-text">整合Spring Security</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#加密解密"><span class="nav-number">3.5.</span> <span class="nav-text">加密解密</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Config-Client额外配置"><span class="nav-number">4.</span> <span class="nav-text">Config-Client额外配置</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#刷新配置"><span class="nav-number">4.1.</span> <span class="nav-text">刷新配置</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#集群配置"><span class="nav-number">5.</span> <span class="nav-text">集群配置</span></a></li></ol></div></div></section></div></aside></div></main><footer id="footer" class="footer" onselectstart="return!1"><div class="footer-inner"><div class="copyright">&copy; 2016 - <span itemprop="copyrightYear">2019</span>&nbsp;&nbsp; <span class="author" itemprop="copyrightHolder">MrBird</span>&nbsp;&nbsp;|<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>&nbsp;&nbsp;UV&nbsp;<span class="busuanzi-value" id="busuanzi_value_site_uv" style="cursor:pointer" title="统计开始时间：2019年7月5日"></span> &nbsp;&nbsp;PV&nbsp;<span class="busuanzi-value" id="busuanzi_value_site_pv" style="cursor:pointer" title="统计开始时间：2019年7月5日"></span></div></div></footer><div class="back-to-top"><span style="font-family:'Source Sans Pro','Helvetica Neue',Arial,sans-serif;font-size:1.2em;font-weight:600">TOP</span></div></div><script type="text/javascript">"[object Function]"!==Object.prototype.toString.call(window.Promise)&&(window.Promise=null)</script><script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script><script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script><script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script><script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script><script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script><script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script><script type="text/javascript">function proceedsearch(){$("body").append('<div class="search-popup-overlay local-search-pop-overlay"></div>').css("overflow","hidden"),$(".search-popup-overlay").click(onPopupClose),$(".popup").toggle();var t=$("#local-search-input");t.attr("autocapitalize","none"),t.attr("autocorrect","off"),t.focus()}var isfetched=!1,isXml=!0,search_path="search.xml";0===search_path.length?search_path="search.xml":search_path.endsWith("json")&&(isXml=!1);var path="/"+search_path,onPopupClose=function(t){$(".popup").hide(),$("#local-search-input").val(""),$(".search-result-list").remove(),$("#no-result").remove(),$(".local-search-pop-overlay").remove(),$("body").css("overflow","")},searchFunc=function(t,e,o){"use strict";$("body").append('<div class="search-popup-overlay local-search-pop-overlay"><div id="search-loading-icon"><i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i></div></div>').css("overflow","hidden"),$("#search-loading-icon").css("margin","20% auto 0 auto").css("text-align","center"),$.ajax({url:t,dataType:isXml?"xml":"json",async:!0,success:function(t){isfetched=!0,$(".popup").detach().appendTo(".header-inner");var n=isXml?$("entry",t).map(function(){return{title:$("title",this).text(),content:$("content",this).text(),url:$("url",this).text()}}).get():t,r=document.getElementById(e),s=document.getElementById(o),a=function(){var t=r.value.trim().toLowerCase(),e=t.split(/[\s\-]+/);e.length>1&&e.push(t);var o=[];if(t.length>0&&n.forEach(function(n){function r(e,o,n,r){for(var s=r[r.length-1],a=s.position,i=s.word,l=[],h=0;a+i.length<=n&&0!=r.length;){i===t&&h++,l.push({position:a,length:i.length});var p=a+i.length;for(r.pop();0!=r.length&&(s=r[r.length-1],a=s.position,i=s.word,p>a);)r.pop()}return c+=h,{hits:l,start:o,end:n,searchTextCount:h}}function s(t,e){var o="",n=e.start;return e.hits.forEach(function(e){o+=t.substring(n,e.position);var r=e.position+e.length;o+='<b class="search-keyword">'+t.substring(e.position,r)+"</b>",n=r}),o+=t.substring(n,e.end)}var a=!1,i=0,c=0,l=n.title.trim(),h=l.toLowerCase(),p=n.content.trim().replace(/<[^>]+>/g,""),u=p.toLowerCase(),f=decodeURIComponent(n.url),d=[],g=[];if(""!=l&&(e.forEach(function(t){function e(t,e,o){var n=t.length;if(0===n)return[];var r=0,s=[],a=[];for(o||(e=e.toLowerCase(),t=t.toLowerCase());(s=e.indexOf(t,r))>-1;)a.push({position:s,word:t}),r=s+n;return a}d=d.concat(e(t,h,!1)),g=g.concat(e(t,u,!1))}),(d.length>0||g.length>0)&&(a=!0,i=d.length+g.length)),a){[d,g].forEach(function(t){t.sort(function(t,e){return e.position!==t.position?e.position-t.position:t.word.length-e.word.length})});var v=[];0!=d.length&&v.push(r(l,0,l.length,d));for(var C=[];0!=g.length;){var $=g[g.length-1],m=$.position,x=$.word,w=m-20,y=m+80;w<0&&(w=0),y<m+x.length&&(y=m+x.length),y>p.length&&(y=p.length),C.push(r(p,w,y,g))}C.sort(function(t,e){return t.searchTextCount!==e.searchTextCount?e.searchTextCount-t.searchTextCount:t.hits.length!==e.hits.length?e.hits.length-t.hits.length:t.start-e.start});var T=parseInt("1");T>=0&&(C=C.slice(0,T));var b="";b+=0!=v.length?"<li><a href='"+f+"' class='search-result-title'>"+s(l,v[0])+"</a>":"<li><a href='"+f+"' class='search-result-title'>"+l+"</a>",C.forEach(function(t){b+="<a href='"+f+'\'><p class="search-result">'+s(p,t)+"...</p></a>"}),b+="</li>",o.push({item:b,searchTextCount:c,hitCount:i,id:o.length})}}),1===e.length&&""===e[0])s.innerHTML='<div id="no-result"><i class="fa fa-search fa-5x" /></div>';else if(0===o.length)s.innerHTML='<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>';else{o.sort(function(t,e){return t.searchTextCount!==e.searchTextCount?e.searchTextCount-t.searchTextCount:t.hitCount!==e.hitCount?e.hitCount-t.hitCount:e.id-t.id});var a='<ul class="search-result-list">';o.forEach(function(t){a+=t.item}),a+="</ul>",s.innerHTML=a}};r.addEventListener("input",a),$(".local-search-pop-overlay").remove(),$("body").css("overflow",""),proceedsearch()}})};$(".popup-trigger").click(function(t){t.stopPropagation(),isfetched===!1?searchFunc(path,"local-search-input","local-search-result"):proceedsearch()}),$(".popup-btn-close").click(onPopupClose),$(".popup").click(function(t){t.stopPropagation()}),$(document).on("keyup",function(t){var e=27===t.which&&$(".search-popup").is(":visible");e&&onPopupClose()})</script></body><script>$(function(){$("a").not(".nav-link,.cloud-tie-join-count,.ignore-href,.jstree-anchor").addClass("animsition-link")});var burst1=new mojs.Burst({left:0,top:0,radius:{5:40},children:{shape:"circle",fill:["red","cyan","orange"],fillOpacity:.8,radiusX:3.5,radiusY:3.5}});document.addEventListener("click",function(a){null==a.target.href&&"footer"!=a.target.className&&"copyright"!=a.target.className&&"author__urls social-icons"!=a.target.className&&"author__avatar"!=a.target.className&&"sidebar sidebar-active"!=a.target.className&&burst1.tune({x:a.pageX,y:a.pageY}).generate().replay()})</script><script type="text/javascript" src="/js/message.js"></script></html><!-- rebuild by neat -->